﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.OleDb;

namespace DAO
{
    public class LoaiHangDAO
    {
        public static List<LoaiHangDTO> LayDanhSach()
        {
            List<LoaiHangDTO> lstLoaiHang = null;
            try
            {
                OleDbConnection cnn = BoKetNoiCSDL.KetNoi();
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM LOAI_HANG", cnn);
                try
                {
                    OleDbDataReader rd = cmd.ExecuteReader();
                    lstLoaiHang = new List<LoaiHangDTO>();
                    while(rd.Read())
                    {
                        LoaiHangDTO loaiHangDto = new LoaiHangDTO();
                        loaiHangDto.MaLoaiHang = (int)rd["MaLoaiHang"];
                        loaiHangDto.TenLoaiHang = (string)rd["TenLoaiHang"];
                        lstLoaiHang.Add(loaiHangDto);
                    }
                    cnn.Close();
                }
                catch (System.Exception ex)
                {
                	if(cnn.State == ConnectionState.Open)
                    {
                        cnn.Close();
                    }
                    throw ex;
                }
            }
            catch (System.Exception ex)
            {
            	throw ex;
            }
            return lstLoaiHang;
        }
    }
}
